package com.jyx;

import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.UUID;
 

import java.io.BufferedReader;
import java.io.FileReader;

/*Scanner in = new Scanner(new File("d:/area.txt"));

String firstLine = in.nextLine().trim();//110000  銆�寳浜競
List<Area> areaList = new ArrayList<Area>();
Area pro = new Area();
String beijing = in.nextLine().trim();
pro.setCode(beijing.substring(0, 6));
pro.setName(beijing.substring(8).trim());



while(in.hasNextLine()){
	pro = new Area();
	String str = in.nextLine().trim();
	String[] abc = str.split("[\\p{Space}]+");
	pro.setId(UUID.randomUUID().toString().replace("-", ""));
	pro.setCode(abc[0]);
	pro.setLevel(1);
	pro.setName(abc[1]);
	pro.setParentId("0");
	
}
*/

public class SysArea {
    public static void main(String[] args) throws Exception {
    	//娓呴櫎鏂囨湰涓殑绌虹櫧琛�
    	/*BufferedReader read = new BufferedReader(new FileReader("d:/area.txt"));
		String line = "";
		while((line=read.readLine())!=null){
			if(!line.equals("")){
				System.out.println(line);
			}
		}
		read.close();*/
		
    	//System.out.println("abcedfg".substring(1, 2));
    	//\r\n涓烘崲琛岀 
    	
        try {
        	FileWriter fw = new FileWriter("D:/1.txt");
            Scanner in = new Scanner(new File("d:/area.txt"));
            
            String firstLine = in.nextLine().trim();//110000  銆�寳浜競
            String pId = firstLine.substring(1,7);//110000
            String proId = firstLine.substring(2,4);//11
            String bjUU = UUID.randomUUID().toString().replace("-", "");
            fw.write("INSERT INTO `zczk`.`sys_area` (`ID`, `C_CREATE_BY`, `C_CREATE_DATE`, `C_UPDATE_BY`, `C_UPDATE_DATE`, `C_DELETE_FLAG`, `C_NAME`, `C_CODE`, `C_PARENT_ID`, `C_LEVEL`) VALUES ('"+bjUU+"', 'admin', '2011-03-17 15:35:52', 'admin', '2016-03-17 15:35:55', 0, '"+ firstLine.substring(9)+"', '"+firstLine.substring(1,7)+"', '0', 1);\r\n");
            String cid = pId.substring(2,4);
            String counId = pId.substring(4);
            int count = 1;
        	String cityUU = "" ;
            while (in.hasNextLine()) {
            	if(count % 10 == 0){
            		fw.flush();
            	}
            	count++;
                String str = in.nextLine().trim();
                String[] abc = str.split("[\\p{Space}]+");//姣忎竴鏉℃暟鎹�k  v
                abc[1] = abc[1].substring(1);
                String nextPro = abc[0].trim().substring(0, 2);
                if(!nextPro.equals(proId)){//闄や簡绗竴涓殑鎵�湁鐨勭渷浠�
                	String proUU = UUID.randomUUID().toString().replace("-", "");
                	fw.write("INSERT INTO `zczk`.`sys_area` (`ID`, `C_CREATE_BY`, `C_CREATE_DATE`, `C_UPDATE_BY`, `C_UPDATE_DATE`, `C_DELETE_FLAG`, `C_NAME`, `C_CODE`, `C_PARENT_ID`, `C_LEVEL`) VALUES ('"+proUU+"', 'admin', '2011-03-17 15:35:52', 'admin', '2016-03-17 15:35:55', 0,'"+ abc[1].replace(" ", "")+"', '"+abc[0]+"', '0', 1);\r\n");
                	bjUU = proUU;
                	proId = nextPro ;
                }else{
                	String nextCid = abc[0].trim().substring(2, 4);
                	if(!cid.equals(nextCid)){//
                		abc[1] = abc[1].substring(1);
                		String nextCityUU = UUID.randomUUID().toString().replace("-", "");
                		fw.write("INSERT INTO `zczk`.`sys_area` (`ID`, `C_CREATE_BY`, `C_CREATE_DATE`, `C_UPDATE_BY`,`C_UPDATE_DATE`, `C_DELETE_FLAG`, `C_NAME`, `C_CODE`, `C_PARENT_ID`, `C_LEVEL`) VALUES ('" +nextCityUU+"', 'admin', '2011-03-17 15:35:52', 'admin', '2016-03-17 15:35:55', 0, '" + abc[1]+"', '"+abc[0]+"', '"+bjUU+"', 2);\r\n");
                		cid = nextCid;
                		cityUU = nextCityUU;
                	}else{
                		String nextCounId = abc[0].substring(4);
                		if(!counId.equals(nextCounId) && !"甯傝緰鍖�.equals(abc[1].substring(2)) && !".equals(abc[1].substring(2))){
                			abc[1] = abc[1].substring(2);
                			fw.write("INSERT INTO `zczk`.`sys_area` (`ID`, `C_CREATE_BY`, `C_CREATE_DATE`, `C_UPDATE_BY`,`C_UPDATE_DATE`, `C_DELETE_FLAG`, `C_NAME`,`C_CODE`, `C_PARENT_ID`, `C_LEVEL`) VALUES ('" +UUID.randomUUID().toString().replace("-", "")+"', 'admin', '2011-03-17 15:35:52', 'admin',"+" '2016-03-17 15:35:55', 0, '" + abc[1]+"', '"+abc[0]+"', '"+cityUU+"', 3);\r\n");
                		}
                	}
                }
            }

            fw.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        
    }
     
}
